package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.domain.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class TestController {
    @Autowired
    UserService userService;
    @GetMapping("/user/{id}")
    public String findById(@PathVariable("id") Integer id, ModelMap map){
        User user=userService.findById(id);
        map.put("user",user);
        System.out.println(user);
        return "forward:/index.jsp";
    }
    @GetMapping("/users")
    public String findByPage(
            @RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",required = false,defaultValue = "2") Integer pageSize, ModelMap map){
        PageInfo<User> pageInfo = userService.findByPage(pageNum,pageSize);
        map.put("data",pageInfo);
        return "forward:/userPro.jsp";
    }

}
